#!/bin/bash

usage()
{
        echo "USAGE : slicelog [ size ]"
}

if [ $# -eq 0 ] ; then
        SIZE=10
elif [ $# -eq 1 ] ; then
        SIZE=$1
else
        usage
        exit 1 ;
fi

if [ ! -d ${HOME}/log ] ; then
	exit 1;
fi

cd ${HOME}/log

find . -type f -name "*.log" -size +${SIZE}M | while read -r LINE 
do
	INDEX=1
	while [ 1 ]
	do
		if [ ! -f ${LINE}.${INDEX} ];then
			break
		fi	
		INDEX=`expr ${INDEX} + 1`
	done

	MVLINE="mv ${LINE} ${LINE}.${INDEX}"
	echo ${MVLINE}
	${MVLINE}
done
